<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 同步和异步, 先执行同步, 在执行异步
    console.log('start');// 1
    setTimeout(function () {
      console.log('你猜我输出在哪');//6
    }, 0);
    console.log('end');// 2
    for (var i = 0; i < 10; i++) {
      console.log(i); // 3
    }
    //---------------------------------------------------------------------------
    console.log('start');//4
    for (var i = 0; i < 3; i++) {
      (function (index) {
        setTimeout(function () {
          console.log(index);//7
        }, 0);
      })(i);
    }
    console.log('end');//5
  </script>
</body>

</html>